package org.ezplatform.office.meeting.task.web.rest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.ezplatform.cloud.api.component.popuser.PopUserScopeUtilService;
import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.cloud.common.controller.BaseController;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.mobile.util.common.service.CommonService;
import org.ezplatform.office.meeting.common.util.MeetingSendMsgUtils;
import org.ezplatform.office.meeting.common.util.MeetingUtils;
import org.ezplatform.office.meeting.info.entity.ApplyRecord;
import org.ezplatform.office.meeting.info.entity.MeetingScope;
import org.ezplatform.office.meeting.info.service.ApplyRecordDingService;
import org.ezplatform.office.meeting.info.service.ApplyRecordService;
import org.ezplatform.office.meeting.info.service.MeetingScopeService;
import org.ezplatform.office.meeting.task.entity.MeetingTaskInfo;
import org.ezplatform.office.meeting.task.service.MeetingTaskInfoService;
import org.ezplatform.util.DateUtils;
import org.ezplatform.util.JsonUtils;
import org.ezplatform.util.StringUtils;
import org.ezplatform.util.UuidUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: TaskInfoController
 * @Description: 会议申请记录控制类
 */
@RestController
@RequestMapping(value = "/api/meeting/taskInfo")
public class MeetingTaskInfoApiController extends BaseController {

	@Autowired
	private MeetingTaskInfoService meetingTaskInfoService;
	
	@Autowired
	private PopUserScopeUtilService popUserScopeUtilService;
	
	@Autowired
	private ApplyRecordService applyRecordService;
	
	@Autowired
	private ApplyRecordDingService applyRecordDingService;
	
	@Autowired
	private MeetingScopeService meetingScopeService;
	
	@Autowired
	private UserApiService userApiService;
	
	@Autowired
	private MeetingSendMsgUtils meetingSendMsgUtils;
	
	@Autowired
	private CommonService commonService;
	
	@Autowired
	private MeetingUtils meetingUtils;
	
	@ApiOperation(value = "实体类是否存在", notes = "实体类是否存在")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "会议任务ID", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/entityIsExist", method = RequestMethod.POST, produces = {"application/json; charset=UTF-8" })
	public OperationResult entityIsExist(String id) {
		MeetingTaskInfo entity = this.meetingTaskInfoService.findOne(id);
		if(entity == null) return OperationResult.buildSuccessResult("notExist");
		else return OperationResult.buildSuccessResult("exist");
	}
	
	/**
	 * 根据会议id获取任务列表
	 * @param request
	 * @return
	 */
	@ApiOperation(value="任务查询", notes="根据会议id获取任务列表")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "applyrecordId", value = "会议申请ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "title", value = "任务标题", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/findTaskList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult findTaskList(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
    	try{
            String page = request.getParameter("page");
            String pageSize = request.getParameter("pageSize");
            String status = request.getParameter("status");
            String userId = request.getParameter("userId");
            String corpId = request.getParameter("corpId");
            String applyrecordId = StringUtils.null2String(request.getParameter("applyrecordId"));
            String title = StringUtils.null2String(request.getParameter("title"));
            
            List<Map> list = this.meetingTaskInfoService.findTaskInfoByPage(status, page, pageSize, applyrecordId, userId, corpId, title);
            
            map.put("data", list);
            map.put("currentPage", Integer.parseInt(page));
           
        }catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
    	return OperationResult.buildSuccessResult(map);
    }
	
    /**
	 * 获取已超期和进行中任务数量
	 * @param request
	 * @return
	 */
	@ApiOperation(value="任务统计", notes="获取已超期和进行中任务数量")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "title", value = "标题", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "applyrecordId", value = "会议申请ID", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/taskInfosCount", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult taskInfosCount(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
    	try{
            String userId = request.getParameter("userId");
            String corpId = request.getParameter("corpId");
            String applyrecordId = StringUtils.null2String(request.getParameter("applyrecordId"));
            String title = StringUtils.null2String(request.getParameter("title"));
            
            //已超期任务
            int expiredCount = this.meetingTaskInfoService.taskInfosCount("0", applyrecordId, userId, corpId, title);
            //进行中任务
            int inProgressCount = this.meetingTaskInfoService.taskInfosCount("1", applyrecordId, userId, corpId, title);
            //已完成任务
            int completeCount = this.meetingTaskInfoService.taskInfosCount("2", applyrecordId, userId, corpId, title);
            
            map.put("expiredCount", expiredCount);
            map.put("inProgressCount", inProgressCount);
            map.put("completeCount", completeCount);
            
            //判断是否是会议申请人和主持人
            if(!"".equals(applyrecordId)){
            	ApplyRecord record = this.applyRecordDingService.findOne(applyrecordId);
                String createdBy = record.getCreatedBy();
                List<String> eScopeList = new ArrayList<>();
                eScopeList.add(record.getEmceeUser());
                List<MeetingScope> emceeUserScopeList = this.meetingScopeService.getMeetingScopeList("oa_meeting_apply_record", "emcee_user", eScopeList,true);
                String emceeUser = "";
                if(emceeUserScopeList!=null && emceeUserScopeList.size()>0){
                	for(MeetingScope m : emceeUserScopeList){
                		emceeUser += m.getScopevalue()+",";
                	}
                }
                String isCreatedOrEmcee = "1";
                if(userId.equals(createdBy) || emceeUser.indexOf(userId)>=0){
                	isCreatedOrEmcee = "0";
                }
                map.put("isCreatedOrEmcee", isCreatedOrEmcee);
            }
    	}catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
    	return OperationResult.buildSuccessResult(map);
    }
    
	/**
	 * 获取任务详情
	 * @param request
	 * @return
	 */
	@ApiOperation(value="任务详情", notes="获取任务详情")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "recordId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "editType", value = "当前页面类型(编辑、新增、查看)", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "taskInfoId", value = "会议任务ID", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getTaskInfo", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getTaskInfo(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
    	try{
            String userId = request.getParameter("userId");
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            String taskInfoId = request.getParameter("taskInfoId");
            String editType = request.getParameter("editType");
            //所属会议
            String recordId = StringUtils.null2String(request.getParameter("recordId"));
            ApplyRecord record = null;
            if(!"".equals(recordId)){
            	record = this.applyRecordDingService.findOne(recordId);
            	if(record == null) {
                	map.put("isDeleted", true);
                	return OperationResult.buildSuccessResult(map);
                }else {
                	map.put("isDeleted", false);
                }
                map.put("recordName", record.getName());
                
    			if(StringUtils.isNotEmpty(recordId)){
    				ApplyRecord applyRecord = this.applyRecordDingService.findOne(recordId);
    				if(applyRecord != null){
    					String emceeUser = applyRecord.getEmceeUser();
    					String memoUser = applyRecord.getMemoUser();
    					String attendUser = applyRecord.getAttendUser();
    					List<Map> maps = this.applyRecordDingService.getAllMeetingUsers(emceeUser, memoUser, attendUser);
    					map.put("limitDataUsers", maps);
    				}
    			}
            }
            if(!"".equals(taskInfoId)){
            	MeetingTaskInfo info = this.meetingTaskInfoService.findOne(taskInfoId);
            	if(info == null) {
                	map.put("isDeleted", true);
                	return OperationResult.buildSuccessResult(map);
                }else {
                	map.put("isDeleted", false);
                }
            	map.put("taskInfo", info);

            	if("".equals(recordId)){
            		recordId = info.getApplyRecordId();
                	record = this.applyRecordDingService.findOne(recordId);
                    map.put("recordName", record.getName());
                }
            	
                Map<String, String> textParams = new HashMap<>();
                textParams.put("corpId", corpId);
                // 负责人
                String responseUserName = applyRecordService.getScopeName("oa_meeting_task_info", info.getResponseUser(), "response_user");
                map.put("responseUserName", responseUserName);
                if(!"view".equals(editType)) {
                	List<Map<String, Object>> resUserMap = this.transformUserScope2Dd(info.getResponseUser(), "oa_meeting_apply_record_scope", "oa_meeting_task_info", "response_user", corpId, token);
                	if(resUserMap != null){
                		map.put("responseUserData", resUserMap);
                	}
                }else{//查看页
                	List<Map> resUserMap2 = applyRecordService.getScopeValues("oa_meeting_task_info", info.getResponseUser(), "response_user");
                    map.put("responseUserData", resUserMap2);
                	//当前用户是否是负责人
                	map.put("isResponse", "1");
                	if(CollectionUtils.isNotEmpty(resUserMap2)) {
                		for(Map m : resUserMap2) {
                			if(userId.equals((String)m.get("value"))){
                        		map.put("isResponse", "0");
                        		break;
                        	}
                		}
                	}
                	//创建人
                	String createdUser = info.getCreatedBy();
//                	List<Map<String, Object>> createdUserData = new ArrayList<>();
                	String createdUserName = applyRecordService.getUserNameById(createdUser);
//                	Map<String, Object> userMap = this.userApiService.getUser(createdUser, corpId, "", token);
//                	if(!userMap.isEmpty()) {
//                		Map<String, Object> m = new HashMap<>();
//                        m.put("key", userMap.get("thirdType"));
//                        m.put("label", userMap.get("userName"));
//                        createdUserData.add(m);
//                    }
                	map.put("createdUserName", createdUserName);
                	
                	//是否是会议申请人和主持人
                	map.put("canEdit", "1");
                    if(userId.equals(record.getCreatedBy())){
                    	map.put("canEdit", "0");
                    }else{
                    	String emceeUser = this.popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", "oa_meeting_apply_record", "emcee_user", StringUtils.null2String(record.getEmceeUser()));
                    	if(StringUtils.isNotEmpty(emceeUser)){
                    		String[] emuser = emceeUser.split("SCOPE");
                    		if(emuser.length>1 && userId.equals(emuser[1])){
                        		map.put("canEdit", "0");
                        	}
                    	}
                    }
                }
            }
            
            // 查询基础设置
//            String noticeType = "";
//            BaseSet baseSet = this.baseSetService.getBaseSetInfo(corpId);
//            if (baseSet != null) {
//                noticeType = baseSet.getNoticeType();
//            }
            String noticeType = commonService.getSysParamValueByMark(corpId, token,"sysImType");
            map.put("noticeType", noticeType);
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
    	return OperationResult.buildSuccessResult(map);
    }
	
	/**
     * 根据scope所需的信息获取scope中的用户,
     * 并将用户信息封装成钉钉salt-ui组件可接受格式
     *
     * @param fieldDataValue
     * @param tableName
     * @param fieldDataTable
     * @param fieldData
     * @return
     */
    private List<Map<String, Object>> transformUserScope2Dd(String fieldDataValue, String tableName, String fieldDataTable, String fieldData, String corpId, String token){
        List<Map<String, Object>> re = new ArrayList<>();
        String scopeTypeStr = this.popUserScopeUtilService.getScopeTypeValue(tableName, fieldDataTable, fieldData, StringUtils.null2String(fieldDataValue));
        String[] scopeTypeArray = scopeTypeStr.split(",");
        if(scopeTypeArray != null && scopeTypeArray.length>0) {
        	String ids = "";
        	for (int i = 0; i < scopeTypeArray.length; i++) {
                String[] info = scopeTypeArray[i].split("SCOPE");
                if (info.length > 1){
                	ids += info[1] + ",";
                }
            }
            Map<String, Object> m = new HashMap<String, Object>();
            List<Map<String, Object>> userList= this.userApiService.getUserList(ids, corpId, "", token);
            if(CollectionUtils.isNotEmpty(userList)) {
            	for(Map<String, Object> userMap : userList) {
                    m.put("text", userMap.get("userName"));
                    m.put("value", userMap.get("id"));
                    re.add(m);
            	}
            }
        }
        return re;
    }
    
    /**
     * 保存任务
     * @param request
     * @return
     */
    @ApiOperation(value = "保存任务", notes = "保存会议任务信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "message", value = "保存会议任务的参数", required = true, paramType = "body", dataType = "String") })
	@RequestMapping(value = "/saveTaskInfo", method = RequestMethod.POST)
	public OperationResult saveTaskInfo(HttpServletRequest request) {
		String token = request.getParameter("token");
		String corpId = request.getParameter("corpId");
		String userId = request.getParameter("userId");
		try {
			String message =  request.getParameter("message");
			Map<String, Object> map = JsonUtils.readValue(message);
			
			MeetingTaskInfo meetingTaskInfo = null;
			String id =  StringUtils.null2String(map.get("id"));
			if (StringUtils.isNotEmpty(id)) {
				meetingTaskInfo = this.meetingTaskInfoService.findOne(id);
			}
			if (meetingTaskInfo == null) {
				meetingTaskInfo = new MeetingTaskInfo();
			}
			
			//任务标题是否重复
			String applyRecordId = StringUtils.null2String(map.get("applyRecordId"));
			String title = StringUtils.null2String(map.get("title"));
			MeetingTaskInfo taskInfo = this.meetingTaskInfoService.findTaskByTitle(applyRecordId, title);
			if(taskInfo != null){
				if(StringUtils.isEmpty(id) || !taskInfo.getId().equals(id)){
					return OperationResult.buildFailureResult("同一会议下的任务标题不能重复");
				}
			}
			meetingTaskInfo.setTitle(title);
			
			if("".equals(StringUtils.null2String(meetingTaskInfo.getId()))){
				meetingTaskInfo.setCreatedBy(userId);
				meetingTaskInfo.setCorpId(corpId);
			}else{
				meetingTaskInfo.setLastModifiedBy(userId);
			}
			
			String comDetails = StringUtils.null2String(map.get("comDetails"));
			meetingTaskInfo.setComDetails(comDetails);
			
			//任务截止时间
            String endTime =  StringUtils.null2String(map.get("endTime"));
            meetingTaskInfo.setEndTime(DateUtils.parseDate(endTime));
            meetingTaskInfo.setContent(StringUtils.null2String(map.get("content")));
            meetingTaskInfo.setApplyRecordId(applyRecordId);
			
			// 负责人
			String responseUser = meetingTaskInfo.getResponseUser();
			if (StringUtils.isEmpty(responseUser)) {
				responseUser = UuidUtils.UUID();
			}
			meetingTaskInfo.setResponseUser(responseUser);
			String resUserId = StringUtils.null2String(map.get("responseUserData"));
			List<String> resUserList = new ArrayList<>();
			String[] userIds = resUserId.split(",");
			resUserList = Arrays.asList(userIds);
			this.meetingScopeService.saveCopeList(resUserList,null,"oa_meeting_task_info","response_user",responseUser,corpId,token);
			
			// 任务进度
			meetingTaskInfo.setProgress(Integer.valueOf(StringUtils.null2String(map.get("progress"))));
			// 任务提醒
			meetingTaskInfo.setRemindTime(Integer.valueOf(StringUtils.null2String(map.get("remindTime"))));
			// 提醒方式
			meetingTaskInfo.setRemindType(StringUtils.null2String(map.get("remindType")));
			meetingTaskInfo = this.meetingTaskInfoService.save(meetingTaskInfo);
			
			if(StringUtils.isEmpty(id)){
				Map<String, Object> ds = new HashMap<>();
				ApplyRecord applyRecord = this.applyRecordDingService.findOne(applyRecordId);
				ds.put("type", "6");
				ds.put("applyRecordId", applyRecordId);
				ds.put("meetingName", applyRecord.getName());
				Date date = DateUtils.parseDate(endTime);
				ds.put("endTime", DateUtils.formatDate(date, "yyyy年MM月dd日"));
				ds.put("title", meetingTaskInfo.getTitle());
				ds.put("id", meetingTaskInfo.getId());
				String noticeUserId = meetingTaskInfo.getCreatedBy();
				ds.put("userId", noticeUserId);
				String noticeUserName = "";
				if(StringUtils.isNoneEmpty(noticeUserId)) {
					Map<String, Object> userMap = userApiService.getUser(noticeUserId, corpId, "", TOKEN);
					if(MapUtils.isNotEmpty(userMap)) {
						noticeUserName = StringUtils.null2String(userMap.get("userName"));
					}
				}
				ds.put("userName", noticeUserName);
				ds.put("userOrg", meetingTaskInfo.getCreatedOrg());
				Map<String, String> idsMap = new HashMap<>();
				idsMap = this.transformUserScopePlatform2Dd(meetingTaskInfo.getResponseUser(), "oa_meeting_task_info", "response_user", corpId, token);
				String idString = idsMap.get("ids");
				String jsonIds = "[" + idsMap.get("jsonIds");
				if(!StringUtils.isEmpty(idString)){
					boolean mobilePush = false;
		            boolean emailPush = false;
		            boolean smsPublish = false;
					String mesgPush = applyRecord.getMessagePush();
					if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
					if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
					if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
					idString = idString.substring(0, idString.length()-1);
					ds.put("userIds", idString);
					ds.put("orgIds", "");
					this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, TOKEN);
					this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
					this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
				}
				if(StringUtils.isNotEmpty(jsonIds)){
					jsonIds = jsonIds.substring(0, jsonIds.length()-1);
					jsonIds += "]";
					this.meetingSendMsgUtils.sendMessage(ds, jsonIds, corpId, token);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("保存失败");
		}
		return OperationResult.buildSuccessResult("保存成功");
	}

    private Map<String, String> transformUserScopePlatform2Dd(String fieldDataValue, String table, String fieldData, String corpId, String token){
        String ids = "", jsonIds = "";
		Map<String, String> result = new HashMap<>();
        String scopeTypeStr = this.popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", table, fieldData, StringUtils.null2String(fieldDataValue));
        String[] scopeTypeArray = scopeTypeStr.split(",");
        if(scopeTypeArray != null && scopeTypeArray.length>0) {
            for (int i = 0; i < scopeTypeArray.length; i++) {
                String[] info = scopeTypeArray[i].split("SCOPE");
                if (info.length > 1){
                    String id  = info[1];
					jsonIds +="{\"10\":\""+id+"\"},";
					ids += id + ",";
//                    List<String> l = this.userApiService.getUserIdBySysOrThird(id, "1", "DD", corpId, token);
//                    if(l!=null && l.size()>0){
//                    	ids += l.get(0) + ",";
//                    }
                }
            }
        }
		result.put("jsonIds", jsonIds);
		result.put("ids", ids);
		return result;
    }
    
    /**
     * 修改任务进度
     * @param request
     * @return
     */
    @ApiOperation(value = "修改任务进度", notes = "修改任务进度或完成任务")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "progress", value = "任务进度", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "comDetails", value = "任务完成情况", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "type", value = "1-修改任务完成情况", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "taskInfoId", value = "任务id", required = true, paramType = "body", dataType = "String") })
	@RequestMapping(value = "/changeProgress", method = RequestMethod.POST)
    public OperationResult changeProgress(HttpServletRequest request) {
    	try {
    		String type = StringUtils.null2String(request.getParameter("type"));
    		String taskInfoId = StringUtils.null2String(request.getParameter("taskInfoId"));
    		if("1".equals(type)){
    			String comDetails = StringUtils.null2String(request.getParameter("comDetails"));
    			this.meetingTaskInfoService.updateDetails(comDetails, taskInfoId);
    		}else{
    			String progress = StringUtils.null2String(request.getParameter("progress"));
            	this.meetingTaskInfoService.updateProgress(Integer.parseInt(progress), taskInfoId);
    		}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return OperationResult.buildSuccessResult("保存失败");
		}
    	return OperationResult.buildSuccessResult("保存成功");
    }
    
    /**
     * 删除任务
     * @param request
     * @return
     */
    @ApiOperation(value = "删除任务", notes = "根据任务id删除任务")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "taskInfoId", value = "任务id", required = true, paramType = "body", dataType = "String") ,
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "body", dataType = "String") ,
		@ApiImplicitParam(name = "corpId", value = "corpId", required = true, paramType = "body", dataType = "String") })
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public OperationResult delete(HttpServletRequest request) {
    	try {
    		String id = StringUtils.null2String(request.getParameter("taskInfoId"));
    		String token = StringUtils.null2String(request.getParameter("token"));
    		String corpId = StringUtils.null2String(request.getParameter("corpId"));
    		//删除相关任务消息
        	this.meetingSendMsgUtils.deleteMessage(Arrays.asList(id), corpId, token);
    		this.meetingTaskInfoService.deleteTask(id);
    	} catch (Exception e) {
    		e.printStackTrace();
    		return OperationResult.buildSuccessResult("删除失败");
    	}
    	return OperationResult.buildSuccessResult("删除成功");
    }
    
    //++++++++++++++++++++++++++++++++++++++++++++++++以下对外api
    
    /**
	 * 获取已超期和进行中任务数量
	 * @param request
	 * @return
	 */
	@ApiOperation(value="任务统计", notes="获取已超期和进行中任务数量")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/taskEICount", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult taskEICount(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
    	try{
            String userId = request.getParameter("userId");
            String corpId = request.getParameter("corpId");
            
            //已超期或进行中任务数量
            int taskCount = this.meetingTaskInfoService.taskInfosCount("3", "", userId, corpId, "");
            //进行中任务
            //int inProgressCount = this.meetingTaskInfoService.taskInfosCount("1", "", userId, corpId, "");
            
            map.put("taskCount", taskCount);
            //map.put("inProgressCount", inProgressCount);
            
    	}catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
    	return OperationResult.buildSuccessResult(map);
    }
    
}
